//
//  HNStudentDetailView.m
//  优学荟管理系统
//
//  Created by 星道 on 17/9/19.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "HNStudentDetailView.h"

@implementation HNStudentDetailView
{
    IBOutlet UIView *_contentView;

    void (^_complete)();
}


+ (instancetype)ShowWithName:(NSString *)name grade:(NSString *)grade className:(NSString *)className count:(NSString *)count complete:(void (^)())complete {

    return [[self alloc] initWithName:name grade:grade className:className count:count complete:complete];
}

- (instancetype)initWithName:(NSString *)name grade:(NSString *)grade className:(NSString *)className count:(NSString *)count complete:(void (^)())complete {

    self = [[[NSBundle mainBundle] loadNibNamed:[HNStudentDetailView description] owner:nil options:nil] lastObject];
    if (self) {

        // 赋值
        _complete = complete;
        self.name.text = name;
        self.grade.text = grade;
        self.className.text = className;
        self.count.text = count;

        // 动画状态
        _contentView.hidden = NO;
        _contentView.alpha = 0;
        self.alpha = 0;

        self.frame = [UIScreen mainScreen].bounds;
        [[UIApplication sharedApplication].keyWindow addSubview:self];

        [self Show];
    }
    return self;
}




/** 显示 */
- (void)Show {

    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 1;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 animations:^{
            _contentView.alpha = 1;
        }];
    }];
}

/** 关闭 */
- (IBAction)Close:(UIButton *)sender {

    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        _complete ? _complete () : nil;
        [self removeFromSuperview];
    }];
}
@end
